package com.geostar.gmp.mina;


import java.nio.charset.Charset;  
import java.nio.charset.CharsetDecoder;  
  
import org.apache.mina.core.buffer.IoBuffer;  
import org.apache.mina.core.session.IoSession;  
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;  
import org.apache.mina.filter.codec.ProtocolDecoderOutput;  

import com.geostar.gmp.model.ProcessModel;
  
public class HDecoder extends CumulativeProtocolDecoder {  
    private final Charset charset;  
  
    public HDecoder(Charset charset) {  
        this.charset = charset;  
    }  
  
    @Override  
    protected boolean doDecode(IoSession arg0, IoBuffer message,  
            ProtocolDecoderOutput arg2) throws Exception {  
        CharsetDecoder cd = charset.newDecoder();  
        String id = message.getString(cd);
        String ip = message.getString(cd);
        String process_name = message.getString(cd);
        String is_running = message.getString(cd);
        String rom_data = message.getString(cd);
        String record_time = message.getString(cd);
          
        ProcessModel pm = new ProcessModel();
        pm.setId(id);
        pm.setIp(ip);
        pm.setProcess_name(process_name);
        pm.setIsRunning(is_running);
        pm.setRom_data(rom_data);
        pm.setRecord_time(record_time);
        
        arg2.write(pm);  
        return true;  
    }  
}  
